package study.java.jdk.jdk8._5_lambda.apple;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;

public class AppleUtils {

    public static List<Apple> filterByColor(List<Apple> dataLt, String color) {
        List<Apple> destLt = new ArrayList<>();
        for (Apple a : dataLt) {
            if (Objects.equals(color, a.getColor())) {
                destLt.add(a);
            }
        }
        return destLt;
    }

    public static List<Apple> filterByWeight(List<Apple> dataLt, int weight) {
        List<Apple> destLt = new ArrayList<>();
        for (Apple a : dataLt) {
            if (a.getWeight() > weight) {
                destLt.add(a);
            }
        }
        return destLt;
    }

    public static List<Apple> filter(List<Apple> dataLt, Predicate<Apple> p) {
        List<Apple> destLt = new ArrayList<>();
        for (Apple a : dataLt) {
            if (p.test(a)) {
                destLt.add(a);
            }
        }
        return destLt;
    }
}
